package com.example.docking.service.impl;

import com.example.docking.dao.jindie.ResponseData;
import com.example.docking.dao.jindie.response.customFiel.CustomFieldData;
import com.example.docking.util.Constants;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.smecloud.apigw.model.ApiResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Type;
import java.util.HashMap;

public class CustomFieldServiceImpl {
    private static final Logger logger = LoggerFactory.getLogger(CustomFieldServiceImpl.class);

    public ResponseData<CustomFieldData> selectMaterial(String customFieldId) {
        logger.info("获取自定义信息");
        Gson gson = new Gson();
        int page = 1; // 初始页码
        int pageSize = 10; // 每页记录数
        HashMap<String, String> map = new HashMap<>();
        map.put("page", String.valueOf(page));
        map.put("page_size", String.valueOf(pageSize));
        map.put("entity_number", customFieldId);
        //根据销售订单获取商品分录：
        DataServiceImpl service = new DataServiceImpl();
        ApiResult detailMateria = null;
        ResponseData<CustomFieldData> detailMateriaData = null;
        try {
            detailMateria = service.SelectDataList(Constants.CUSTOM_FIELD, map, "");
            Type MateriaDataType = new TypeToken<ResponseData<CustomFieldData>>() {
            }.getType();
            detailMateriaData = gson.fromJson(detailMateria.getBody(), MateriaDataType);
            logger.info("获取自定义信息：" + detailMateriaData.getErrcode());
            logger.info("获取自定义信息：返回" + detailMateriaData.getDescription());
            logger.info("获取自定义信息：返回" + detailMateriaData.getData());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return detailMateriaData;
    }

    public static void main(String[] args) {
        CustomFieldServiceImpl customFieldService = new CustomFieldServiceImpl();
        customFieldService.selectMaterial(Constants.SAL_BILL_ORDER);

    }
}
